package com.ruoyi.project.countrybus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.countrybus.domain.SysDriver;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.countrybus.domain.SysCustomer;
import com.ruoyi.project.countrybus.service.ISysCustomerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 乘客信息Controller
 * 
 * @author yangwenbo
 * @date 2022-04-05
 */
//@Api("乘客信息管理")
@RestController
@RequestMapping("/countrybus/customer")
public class SysCustomerController extends BaseController
{
    @Autowired
    private ISysCustomerService sysCustomerService;

    /**
     * 查询乘客信息列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:customer:list')")
    @GetMapping("/list")
//    @ApiOperation("获取乘客列表")
    public TableDataInfo list(SysCustomer sysCustomer)
    {
        startPage();
        List<SysCustomer> list = sysCustomerService.selectSysCustomerList(sysCustomer);
        return getDataTable(list);
    }

    /**
     * 导出乘客信息列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:customer:export')")
    @Log(title = "乘客信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCustomer sysCustomer)
    {
        List<SysCustomer> list = sysCustomerService.selectSysCustomerList(sysCustomer);
        ExcelUtil<SysCustomer> util = new ExcelUtil<SysCustomer>(SysCustomer.class);
        util.exportExcel(response, list, "乘客信息数据");
    }

    /**
     * 获取乘客信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:customer:query')")
//    @ApiOperation("获取乘客详情信息")
//    @ApiImplicitParam(name = "customerId", value = "乘客ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return AjaxResult.success(sysCustomerService.selectSysCustomerByCustomerId(customerId));
    }


    /**
     * 获取乘客信息详细信息，通过账号
     */
//    @ApiOperation("通过账号获取乘客详情信息")
//    @ApiImplicitParam(name = "customerName", value = "乘客账号", required = true, dataType = "string", paramType = "path", dataTypeClass = String.class)
    @GetMapping(value = "/name/{customerName}")
    public AjaxResult getInfoByName(@PathVariable("customerName") String customerName)
    {
        return AjaxResult.success(sysCustomerService.selectSysCustomerByCustomerName(customerName));
    }

    /**
     * 新增乘客信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:customer:add')")
//    @ApiOperation("新增乘客信息")
    @Log(title = "乘客信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCustomer sysCustomer)
    {
        return toAjax(sysCustomerService.insertSysCustomer(sysCustomer));
    }

    /**
     * 修改乘客信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:customer:edit')")
//    @ApiOperation("修改乘客信息")
    @Log(title = "乘客信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCustomer sysCustomer)
    {
        return toAjax(sysCustomerService.updateSysCustomer(sysCustomer));
    }

    /**
     * 删除乘客信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:customer:remove')")
    @Log(title = "乘客信息", businessType = BusinessType.DELETE)
//    @ApiOperation("删除乘客信息")
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(sysCustomerService.deleteSysCustomerByCustomerIds(customerIds));
    }

//    @ApiOperation("乘客端登陆验证")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "customerName", value = "乘客账号", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class),
//            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
//    })
//    @GetMapping("/customerlogin/{customerName}/{password}")
//    public AjaxResult customerlogin(@PathVariable("customerName") String customerName,@PathVariable("password") String password)
//    {
//
//        SysCustomer sysCustomer = sysCustomerService.selectSysCustomerByCustomerName(customerName);
//        String pass = sysCustomer.getPassword();
//
//        if (StringUtils.equals(pass,password))
//        {
//            return AjaxResult.success(sysCustomer);
////            return AjaxResult.success("登陆成功");
//        }
//        else
//        {
//            return error("用户不存在");
//        }
//    }

//    @ApiOperation("乘客端找回密码")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "phonenumber", value = "乘客手机号", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class),
//            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
//    })
    @GetMapping("/findpassword/{phonenumber}/{password}")
    public AjaxResult customerchangepassword(@PathVariable("phonenumber") String phonenumber,@PathVariable("password") String password)
    {

        SysCustomer sysCustomer = sysCustomerService.selectSysCustomerByCustomerPhonenumber(phonenumber);
        sysCustomer.setPassword(password);

        return toAjax(sysCustomerService.updateSysCustomer(sysCustomer));
    }


}
